<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>添加一言</title>
    <%@ include file="inc/css.jsp" %>
</head>
<body>

<div id="posts" class="wrapper">

    <%@ include file="inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">一言列表</h1>
                <h4 style="margin-left: 10px;" id="showH">——添加一言</h4>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <form id="infoForm" method="post" action="backend/paper/save" class="form-horizontal nice-validator n-default" role="form" novalidate="novalidate">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">内容:</label>

                                <div class="col-sm-6">
                                    <textarea id="content" name="content" class="form-control" maxlength="2000" style="resize: none" placeholder="请输入详情描述，最多2000字" cols="40" rows="8"></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">类型:</label>

                                <div class="col-sm-4">
                                    <select class="form-control" id="typeList" name="typeId" style="width: 150px;">
                                        <option value="1">短叹</option>
                                        <option value="2">长吟</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">信纸:</label>

                                <div class="col-sm-4">
                                    <select class="form-control" id="paperList" name="paperId" style="width: 150px;">
                                        <option value="">请选择信纸</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-6" style="text-align: center">
                                    <button type="button" class="btn btn-primary" onclick="_paperInfo.fn.subInfo()">确定添加</button>
                                    <button type="button" class="btn btn-primary" onclick="_paperInfo.fn.goBack()">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!-- /.panel-body -->

                </div>
                <!-- /.panel -->
            </div>
        </div>

    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<%@ include file="inc/footer.jsp" %>

</body>

<script type="text/javascript">
    var _paperInfo = {
        fn: {
            init: function () {
                _paperInfo.fn.getPaperList();
            },
            checkData: function () {
                var flag = true;
                var content = $('#content').val();
                var paperId = $('#paperList option:selected').val();

                if (null == content || content == '') {
                    $leoman.notify('纸条内容不能为空', "error");
                    flag = false;
                    return;
                }

                if (null == paperId || paperId == '') {
                    $leoman.notify('请选择信纸', "error");
                    flag = false;
                    return;
                }

                return flag;
            },
            subInfo: function () {
                // 所有的验证通过后，执行新增操作
                if (_paperInfo.fn.checkData()) {
                    $("#infoReduceDialogModal").modal("show");

                    $("#infoForm").ajaxSubmit({
                        url: _basePath + "backend/paper/save",
                        dataType: "json",
                        success: function (data) {
                            $('#infoReduceDialogModal').modal("hide");
                            if (data == 1) {
                                _paperInfo.fn.goBack();
                            } else {
                                $leoman.notify("操作失败", "error");
                            }
                        }
                    });
                }
            },
            getPaperList: function () {
                $leoman.ajax("common/findListByType", {
                    type: 1
                }, function (result) {
                    if (null != result) {
                        var content = "";
                        jQuery.each(result, function (i, item) {
                            content += "<option value='" + item.id + "'>" + item.name + "</option>";
                        });
                        $('#paperList').append(content);
                    } else {
                        $leoman.notify("获取信纸信息失败", "error");
                    }
                });
            },
            goBack: function () {
                window.location.href = "backend/paper/index";
            }
        }
    }

    $(document).ready(function () {
        _paperInfo.fn.init();
    });

</script>

</html>